<template>
    <div id="chart-diagram" style="background-color: whitesmoke; width: 1000px; height: 1000px;">
    </div>
</template>

<script setup>
    import {onMounted} from 'vue';
    import go from "gojs";

    let myDiagram = null;

    const init = () => {
        const $ = go.GraphObject.make


        let myDiagram = new go.Diagram("chart-diagram", {
            'grid.visible': true, // 显示网格
            'clickCreatingTool.archetypeNodeData': {category: 'Normal', text: '新节点', notice: ''}, // 双击新建节点(可以写入节点的默认信息)；；
            'toolManager.hoverDelay': 100, // tooltip提示显示延时
            'toolManager.toolTipDuration': 10000, // tooltip持续显示时间
            allowMove: true, // 允许拖动画板
            allowDragOut: true, // 允许拖拽节点
            allowDelete: true, // 允许删除节点
            allowCopy: true, // 允许复制节点
            allowClipboard: true, // 允许粘贴节点
            layout: $(go.TreeLayout, { angle: 90, layerSpacing: 85,nodeSpacing:80 })
        });


        myDiagram.nodeTemplate =
            $(go.Node, "Auto", // 使用Auto布局
                {
                    background: "#ff00ff",
                }, // 设置模板样式
                $(go.Shape, "RoundedRectangle", {fill: "white"}, // 节点形状为圆角矩形，填充为白色
                    new go.Binding("fill", "color") // 绑定填充颜色到数据属性
                ),
                $(go.TextBlock, {margin: 15, font: 'bold 15pt sans-serif'}, // 文本块，边距为8
                    new go.Binding("text", "text") // 绑定文本到数据属性的key字段
                )
            );

        myDiagram.linkTemplate =
            $(go.Link,
                {
                    // 链路路由应避开节点
                    routing: go.Link.AvoidsNodes,
                    corner: 10,
                    curve: go.Link.JumpGap
                },

                $(go.Shape,{strokeWidth: 3},
                    new go.Binding("stroke", "color"),  // shape.stroke = data.color
                    ),  // shape.strokeWidth = data.thick
                $(go.Shape,
                    {toArrow: "OpenTriangle", fill: null},
                    new go.Binding("stroke", "color"),  // shape.stroke = data.color
                   new go.Binding("strokeWidth", "thick")),  // shape.strokeWidth = data.thick

            );



        myDiagram.model = new go.GraphLinksModel(
                    [{key: "Hello",text:'Hello',color:'red'},{key: "World!",text:'world',color:'green'},{key: "node3",text:'node3',color:'orange'}],   // two node data, in an Array
                    [{from: "Hello", to: "World!",color:'red'},{from: "Hello", to: "node3",color:'green'}]  // one link data, in an Array
         );
    };

    onMounted(() => {
        init();
    });


</script>

<style scoped>

</style>